package com.qf.web.blog.controller;

import com.qf.api.blog.service.WikiCatalogService;
import com.qf.api.blog.service.WikiService;
import com.qf.api.front.vo.WikiCatalogVO;
import com.qf.api.front.vo.WikiVO;
import com.qf.api.sys.mybatis.page.BaseController;
import com.qf.api.sys.mybatis.page.PageResult;
import com.qf.core.response.ResponseResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: sin
 * @Date: 2025/6/3 14:17
 * @Description:
 **/
@Tag(name = "01.知识库")
@RestController
@RequestMapping("/blog/wiki")
public class WikiController extends BaseController {

    @Autowired
    private WikiService wikiService;

    @Autowired
    private WikiCatalogService wikiCatalogService;

    @GetMapping
    public ResponseResult<PageResult<WikiVO>> getWikiPage(@RequestParam(name = "title",required = false) String title) {
        startPage();
        List<WikiVO> list = wikiService.getWikiPage(title);
        return ResponseResult.success(getData(list));
    }

    @GetMapping("/catalog/{id}")
    public ResponseResult<List<WikiCatalogVO>> getWikiCatalog(@PathVariable("id") Long wikiId) {
        return ResponseResult.success(wikiCatalogService.getFrontWikiCatalog(wikiId));
    }

    /**
     * 拿知识库Id获取文章Id，目的构建前端请求链接
     **/
    @GetMapping("/article/{id}")
    public ResponseResult<Long> getWikiArticleId(@PathVariable("id") Long catalogId) {
        return ResponseResult.success(wikiCatalogService.getById(catalogId).getArticleId());
    }
}
